package tech.aistar.corejava.day15.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * 创建一个**可重用**固定个数的线程池，以共享的无界队列方式来运行这些线程。
 * @date 2019/8/3 0003
 */
public class FixedThreadPoolDemo {
    public static void main(String[] args) {
        //创建了一个固定个数为3的可重用的固定个数的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        for (int i = 0; i < 10; i++) {
            executorService.execute(()->{
                System.out.println(Thread.currentThread().getName()+",正在被执行...");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
